package com.google.code.rgbgoesbetween.services;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.util.Log;


public class SHA1PassHasher implements PasswordHasher {

	/**
	 * @return the hash of the string using the SHA1  function
	 * @throws NullPointerException if "password" is null
	 * 
	 */
	@Override
	public String hashPassword(String password) {
		MessageDigest digest = null;
        try {
                digest = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
                Log.e("SESSION_MANAGER", e.getMessage());
        }
		digest.reset();
		byte[] data = digest.digest(password.getBytes());
		return String.format("%0" + (data.length*2) + "X", new BigInteger(1, data));
	}

}
